<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        print_r(C('DATA_CACHE_TYPE'));
    }
    public function getdata(){
        $user = M('user');
        $code = $user->where('id=1')->find();
        dump($code);
    }
    // 向数据库添加数据
    public function adds(){
        // $data = array(
        //     'name'=>'吴三省',
        //     'age'=>42
        // );
        $user = M('user');
    //    $user->add($data);
        $num = $user->count();
        echo $num;
    }
    // 删除数据
    public function del(){
        $user = M('user');
       $user->where('id=4')->delete();
    }
    public function view1(){
        $this->assign('now',time());
        $this->display();
    }
    // 加载upload页
    public function upload(){
        $this->display();
    }
    // 图片上传
    public function upload_do(){
        $upload = new\Think\Upload();// 实例化上传类
        $upload->maxSize = 1024*1024*2;
        $upload->exts = array('jpg','png');
        $upload->rootPath = './uploads/';
        $upload->savePath = '';
        $infor = $upload->upload();
        if(!$infor){
            $this->error($upload->getError());
        }else{
            $baseURL = 'uploads/'.$infor['file']['savepath'].$infor['file']['savename'];
            echo $baseURL;
        }
    }
    //生成验证码
    public function verify(){
        $verify = new\Think\Verify();
        $verify->entry();
    }
    //生成验证码
    public function code(){
        $this->display();
    }
   //检测验证码
    public function code_do(){
        $code = I('code');
        $verify = new\Think\Verify();
        if($verify->check($code)){
            $this->success('验证成功！');
        }else{
            $this->error('验证失败！');
        }
        // $this->display();
    }
}